package com.example.testhiber.initPackage.test.testhtmlPicture;

import com.example.testhiber.initPackage.business.utils.FileUtils;
import com.example.testhiber.initPackage.business.utils.StringKit;

import java.io.File;
import java.util.ResourceBundle;
import java.util.UUID;

/**
 * @version v1.0
 * @ProjectName: testhiber
 * @ClassName: PictureSubcontracting
 * @Description: TODO(图片分割固定数量 到不同的文件夹，设定 2000个文件移动一次 ，初始化文件路径配置，目标路径配置)
 * @Author: fcy
 * @Date: 2020/10/26 0026 14:27
 */
public class PictureSubcontracting {






    public static String pictureSubPic(){

        ResourceBundle rb = ResourceBundle.getBundle("application");
        String fileInitPath = rb.getString("fileInitPath");//初始化文件目录
        String fileToPath = rb.getString("fileToPath");//分割到的文件目录
        String fileMaxToMove = rb.getString("fileMaxToMove");//设置多少个文件就移动到新的目录
        Integer fileMaxToMoveInt = Integer.parseInt(fileMaxToMove);

        File file = new File(fileInitPath);
        String filelist[] = file.list();
        Integer count = 1;

        String toPathUUID = "";
        for (String s:filelist){
            System.out.println(s);
            String fromPath=fileInitPath + s;//初始化文件路径

            if("".equals(StringKit.toString(toPathUUID))){
                toPathUUID = UUID.randomUUID().toString().replaceAll("-","");
                FileUtils.createFiles(fileToPath + toPathUUID);
            }

            String toPath= fileToPath + toPathUUID + File.separator + s;
            FileUtils.moveFile(fromPath,toPath);

            if(count>2){
                count=0;
                toPathUUID="";
            }
            count++;
        }
        System.out.println(count);
        return "";
    }


    public static void main(String[] args) {
        pictureSubPic();
    }








}
